#ifndef __CacheSim__Cache__
#define __CacheSim__Cache__

#include "Parser.h"

class Cache
{
public:
	Cache(unsigned size, unsigned lineSize, unsigned adressSize = 64);
	~Cache();

	void performCacheOperation(Parser::TraceElement& element, unsigned& hitCounter, unsigned& missCounter);
	virtual float getFilled() = 0;

protected:
	//void (Cache::*function) --> function pointer: read, store, modify, load, functions
	void performCacheOperation(unsigned adress, unsigned operationSize, void (Cache::*function)(unsigned, unsigned), unsigned& hitCounter, unsigned& missCounter);
	void read(unsigned adress, unsigned size);
	void store(unsigned adress, unsigned size);
	void load(unsigned adress, unsigned size);
	void modify(unsigned adress, unsigned size);

	int log2(int x);
	//calculates the Tag Value, the Index value and the Offset value of the current adress
	void calculateAdress(unsigned adress);
	int getConsumedBytes();

	virtual bool checkHit() = 0; // true = hit, false = miss

protected:
	unsigned size;
	unsigned cacheLineSize;
	unsigned lines;

	unsigned offsetBits;
	int tagBits;
	unsigned indexBits;
	unsigned currentIndex;
	int currentTag;
	unsigned currentOffset;
	unsigned adressSize;
};

#endif